﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using AdaptiveAgents.Distributions;

namespace GameAnalyzer
{
    public partial class frmDistribution : Form
    {
        public frmDistribution()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Creates a step graph (graph of straight lines)
        /// </summary>
        /// <param name="title">TITLE of the chart</param>
        /// <param name="x">vector of x axis points</param>
        /// <param name="y">vector of y axis points</param>
        public void createStepGraph(String title, double[] x, double[] y)
        {
            //Create the distribution graph
            GraphPane myPane = zgcDist.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = title;
            myPane.XAxis.Title.Text = "";
            myPane.YAxis.Title.Text = "Competence";

            // Generate some values
            PointPairList list = new PointPairList();
            for (int i = 0; i < x.Length; ++i)
            {
                list.Add(x[i], y[i]);
            }

            // Add a red curve with circle symbols
            LineItem curve = myPane.AddCurve("Step", list, Color.Red, SymbolType.None);
            curve.Line.Width = 1.5F;
            // Fill the area under the curve
            curve.Line.Fill = new Fill(Color.White, Color.FromArgb(60, 190, 50), 90F);
            // Fill the symbols with white to make them opaque
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 5;

            // Set the curve type to forward steps
            curve.Line.StepType = StepType.ForwardStep;
            
            // Limit the X axis to max value of the X array
            curve.GetXAxis(myPane).Scale.MaxGrace = 0f;

            // Calculate the Axis Scale Ranges
            zgcDist.AxisChange();
        }

        /// <summary>
        /// Creates Steps from point array
        /// </summary>
        /// <param name="title">TITLE of the chart</param>
        /// <param name="curveName">TITLE of the curve</param>
        /// <param name="sample">point array</param>
        public void createSteps(String title, String curveName, AdaptiveAgents.Distributions.Point[] sample)
        {
            //Create the distribution graph
            GraphPane myPane = zgcDist.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = title;
            myPane.XAxis.Title.Text = "";
            myPane.YAxis.Title.Text = "Competence";

            PointPairList list = new PointPairList();

            //Get points and distribution values
            foreach (AdaptiveAgents.Distributions.Point point in sample)
                list.Add(point.X, point.Y);

            // Add a red curve with circle symbols
            LineItem curve = myPane.AddCurve(curveName, list, Color.Red, SymbolType.None);
            curve.Line.Width = 1.5F;
            // Fill the area under the curve
            curve.Line.Fill = new Fill(Color.White, Color.FromArgb(60, 190, 50), 90F);
            // Fill the symbols with white to make them opaque
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 5;

            // Set the curve type to forward steps
            curve.Line.StepType = StepType.NonStep;

            // Limit the X axis to max value of the X array
            curve.GetXAxis(myPane).Scale.MaxGrace = 0f;

            // Limit the X axis to min value of the X array
            curve.GetXAxis(myPane).Scale.MinGrace = 0f;

            // Calculate the Axis Scale Ranges
            zgcDist.AxisChange();
        }

        private void frmDistribution_Load(object sender, EventArgs e)
        {
            
        }

        /// <summary>
        /// Creates a curve graph
        /// </summary>
        /// <param name="title">TITLE of the chart</param>
        /// <param name="curveName">TITLE of the curve</param>
        /// <param name="sample">point array</param>
        public void createCurve(String title, String curveName, AdaptiveAgents.Distributions.Point[] sample)
        {
            //Create the distribution graph
            GraphPane myPane = zgcDist.GraphPane;

            // Set the title and axis labels
            myPane.Title.Text = title;
            myPane.XAxis.Title.Text = "";
            myPane.YAxis.Title.Text = "Competence";

            PointPairList list = new PointPairList();

            //Get points and distribution values
            foreach (AdaptiveAgents.Distributions.Point point in sample) 
                list.Add(point.X, point.Y);

            // Add a red curve with circle symbols
            LineItem curve = myPane.AddCurve(curveName, list, Color.Red, SymbolType.None);
            curve.Line.Width = 1.5F;
            // Fill the area under the curve
            curve.Line.Fill = new Fill(Color.White, Color.FromArgb(60, 190, 50), 90F);
            // Fill the symbols with white to make them opaque
            curve.Symbol.Fill = new Fill(Color.White);
            curve.Symbol.Size = 5;

            // Set the curve type to forward steps
            curve.Line.StepType = StepType.NonStep;

            // Limit the X axis to max value of the X array
            curve.GetXAxis(myPane).Scale.MaxGrace = 0f;

            // Limit the X axis to min value of the X array
            curve.GetXAxis(myPane).Scale.MinGrace = 0f;

            // Calculate the Axis Scale Ranges
            zgcDist.AxisChange();
        }
    }
}
